package com.uam.core.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 全局分布式锁
 * @author heguanglong
 */
@Configuration
public class RedissonConfigure {
    @Value("${spring.redis.host}")
    private String address;
    @Value("${spring.redis.password}")
    private String password;
    @Value("${spring.redis.port}")
    private Integer port;


    @Bean
    public RedissonClient createRedisson() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://" + address + ":" + port)
                .setTimeout(10000)
                .setRetryAttempts(6)
                .setRetryInterval(3000)
                .setPassword(password)
        ;
        return Redisson.create(config);
    }
}
